]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_omdoc/cic2content.ml
first moogle template checkin
[helm.git] / helm / ocaml / cic_omdoc / cic2content.ml
index 0f23afb5691b7721b0b67b2f9e73ce267d3a9147..49e2e23ad11e738442faa10d8dca38c597ba937a 100644 (file)
@@ -28,7 +28,7 @@
 (*                           PROJECT HELM                                 *)
 (*                                                                        *)
 (*                Andrea Asperti <asperti@cs.unibo.it>                    *)
-(*                             16/62003                                   *)
+(*                             16/6/2003                                   *)
 (*                                                                        *)
 (**************************************************************************)
 
@@ -70,7 +70,7 @@ let rec occur uri =
     | C.Var _ -> false
     | C.Meta _ -> false
     | C.Sort _ -> false
-    | C.Implicit -> raise NotImplemented
+    | C.Implicit _ -> assert false
     | C.Prod (_,s,t) -> (occur uri s) or (occur uri t)
     | C.Cast (te,ty) -> (occur uri te)
     | C.Lambda (_,s,t) -> (occur uri s) or (occur uri t) (* or false ?? *)
@@ -405,27 +405,18 @@ build_def_item seed id n t ~ids_to_inner_sorts ~ids_to_inner_types =
  let module K = Content in
   try
    let sort = Hashtbl.find ids_to_inner_sorts id in
-   (match name_of n with
-     Some "w" -> prerr_endline ("build_def: " ^ sort );
-   | _ -> ());
    if sort = "Prop" then
-       (prerr_endline ("entro");
-       let p = 
+       (let p = 
         (acic2content seed ?name:(name_of n) ~ids_to_inner_sorts  ~ids_to_inner_types t)
        in 
-        (match p.K.proof_name with
-           Some "w" -> prerr_endline ("TUTTO BENE:");
-         | Some s -> prerr_endline ("mi chiamo " ^ s);
-         | _ -> prerr_endline ("ho perso il nome"););
-      prerr_endline ("esco"); `Proof p;)
+        `Proof p;)
    else 
-      (prerr_endline ("siamo qui???");
       `Definition
         { K.def_name = name_of n;
           K.def_id = gen_id definition_prefix seed; 
           K.def_aref = id;
           K.def_term = t
-        })
+        }
   with
    Not_found -> assert false
 
@@ -546,18 +537,37 @@ and acic2content seed ?name ~ids_to_inner_sorts ~ids_to_inner_types t =
           generate_exact seed t id name ~ids_to_inner_types
         else raise Not_a_proof
     | C.AMutCase (id,uri,typeno,ty,te,patterns) ->
-        let inductive_types =
+        let inductive_types,noparams =
            (match CicEnvironment.get_obj uri with
                Cic.Constant _ -> assert false
              | Cic.Variable _ -> assert false
              | Cic.CurrentProof _ -> assert false
-             | Cic.InductiveDefinition (l,_,_) -> l 
+             | Cic.InductiveDefinition (l,_,n) -> l,n 
            ) in
-        let (_,_,_,constructors) = List.nth inductive_types typeno in 
+        let (_,_,_,constructors) = List.nth inductive_types typeno in
+        let name_and_arities = 
+          let rec count_prods =
+            function 
+               C.Prod (_,_,t) -> 1 + count_prods t
+             | _ -> 0 in
+          List.map 
+            (function (n,t) -> Some n,((count_prods t) - noparams)) constructors in
+        let pp = 
+          let build_proof p (name,arity) =
+            let rec make_context_and_body c p n =
+              if n = 0 then c,(aux p)
+              else 
+                (match p with
+                   Cic.ALambda(idl,vname,s1,t1) ->
+                     let ce = 
+                       build_decl_item seed idl vname s1 ~ids_to_inner_sorts in
+                     make_context_and_body (ce::c) t1 (n-1)
+                   | _ -> assert false) in
+             let context,body = make_context_and_body [] p arity in
+               K.ArgProof
+                {body with K.proof_name = name; K.proof_context=context} in
+          List.map2 build_proof patterns name_and_arities in
         let teid = get_id te in
-        let pp = List.map2 
-          (fun p (name,_) -> (K.ArgProof (aux ~name p))) 
-           patterns constructors in
         let context,term =
           (match 
              build_subproofs_and_args 
@@ -668,10 +678,9 @@ and inductive seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
       if n<0 then raise NotApplicable
       else 
         let method_name =
-          if (uri_str = "cic:/Coq/Init/Logic_Type/exT_ind.con" or
-              uri_str = "cic:/Coq/Init/Logic/ex_ind.con") then "Exists"
-          else if uri_str = "cic:/Coq/Init/Logic/and_ind.con" then "AndInd"
-          else if uri_str = "cic:/Coq/Init/Logic/False_ind.con" then "FalseInd"
+          if UriManager.eq uri HelmLibraryObjects.Logic.ex_ind_URI then "Exists"
+          else if UriManager.eq uri HelmLibraryObjects.Logic.and_ind_URI then "AndInd"
+          else if UriManager.eq uri HelmLibraryObjects.Logic.false_ind_URI then "FalseInd"
           else "ByInduction" in
         let prefix = String.sub uri_str 0 n in
         let ind_str = (prefix ^ ".ind") in 
@@ -705,7 +714,6 @@ and inductive seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
         let subproofs,other_method_args =
           build_subproofs_and_args seed other_args
              ~ids_to_inner_types ~ids_to_inner_sorts in
-        prerr_endline "****** end other *******"; flush stderr;
         let method_args=
           let rec build_method_args =
             function
@@ -725,8 +733,7 @@ and inductive seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
                                 build_decl_item 
                                   seed idl n s1 ~ids_to_inner_sorts in
                               if (occur ind_uri s) then
-                                (  prerr_endline ("inductive:" ^ (UriManager.string_of_uri ind_uri) ^ (CicPp.ppterm s)); flush stderr; 
-                                   match t1 with
+                                ( match t1 with
                                    Cic.ALambda(id2,n2,s2,t2) ->
                                      let inductive_hyp =
                                        `Hypothesis
@@ -741,7 +748,7 @@ and inductive seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
                                      (ce::inductive_hyp::context,body)
                                  | _ -> assert false)
                               else 
-                                (  prerr_endline ("no inductive:" ^ (UriManager.string_of_uri ind_uri) ^ (CicPp.ppterm s)); flush stderr; 
+                                ( 
                                 let (context,body) = bc (t,t1) in
                                 (ce::context,body))
                             | _ , t -> ([],aux t) in
@@ -765,7 +772,7 @@ and inductive seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
                 K.conclude_method = method_name;
                 K.conclude_args =
                   K.Aux (string_of_int no_constructors) 
-                  ::K.Term (C.AAppl id ((C.AConst(idc,uri,exp_named_subst))::params_and_IP))
+                  ::K.Term (C.AAppl(id,((C.AConst(idc,uri,exp_named_subst))::params_and_IP)))
                   ::method_args@other_method_args;
                 K.conclude_conclusion = 
                    try Some 
@@ -782,9 +789,8 @@ and rewrite seed name id li ~ids_to_inner_types ~ids_to_inner_sorts =
   let module C = Cic in
   match li with 
     C.AConst (sid,uri,exp_named_subst)::args ->
-      let uri_str = UriManager.string_of_uri uri in
-      if uri_str = "cic:/Coq/Init/Logic/eq_ind.con" or
-         uri_str = "cic:/Coq/Init/Logic/eq_ind_r.con" then 
+      if UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_URI or
+         UriManager.eq uri HelmLibraryObjects.Logic.eq_ind_r_URI then 
         let subproofs,arg = 
           (match 
              build_subproofs_and_args 
@@ -861,6 +867,42 @@ let map_conjectures
   (id,n,context',ty)
 ;;
 
+(* map_sequent is similar to map_conjectures, but the for the hid
+of the hypothesis, which are preserved instead of generating
+fresh ones. We shall have to adopt a uniform policy, soon or later *)
+
+let map_sequent ((id,n,context,ty):Cic.annconjecture) =
+ let module K = Content in
+ let context' =
+  List.map
+   (function
+       (id,None) -> None
+     | (id,Some (name,Cic.ADecl t)) ->
+         Some
+          (* We should call build_decl_item, but we have not computed *)
+          (* the inner-types ==> we always produce a declaration      *)
+          (`Declaration
+            { K.dec_name = name_of name;
+              K.dec_id = id; 
+              K.dec_inductive = false;
+              K.dec_aref = get_id t;
+              K.dec_type = t
+            })
+     | (id,Some (name,Cic.ADef t)) ->
+         Some
+          (* We should call build_def_item, but we have not computed *)
+          (* the inner-types ==> we always produce a declaration     *)
+          (`Definition
+             { K.def_name = name_of name;
+               K.def_id = id; 
+               K.def_aref = get_id t;
+               K.def_term = t
+             })
+   ) context
+ in
+  (id,n,context',ty)
+;;
+
 let rec annobj2content ~ids_to_inner_sorts ~ids_to_inner_types = 
   let module C = Cic in
   let module K = Content in