]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/acic_content/termAcicContent.ml
Non-linear patterns are now allowed in notations.
[helm.git] / helm / software / components / acic_content / termAcicContent.ml
index f6b1b68aa3958d50deb92c1ec97a4c82aaee7322..edb22c9442c5aaa53c9e43c7ea8b7a54b728c2e1 100644 (file)
@@ -42,7 +42,7 @@ type term_info =
   }
 
 let get_types uri =
-  let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
+  let o,_ = CicEnvironment.get_obj CicUniv.oblivion_ugraph uri in
     match o with
       | Cic.InductiveDefinition (l,_,lpsno,_) -> l, lpsno 
       | _ -> assert false
@@ -103,14 +103,14 @@ let ast_of_acic0 ~output_type term_info acic k =
     | Cic.ASort (id,Cic.Prop) -> idref id (Ast.Sort `Prop)
     | Cic.ASort (id,Cic.Set) -> idref id (Ast.Sort `Set)
     | Cic.ASort (id,Cic.Type u) -> idref id (Ast.Sort (`Type u))
-    | Cic.ASort (id,Cic.CProp) -> idref id (Ast.Sort `CProp)
+    | Cic.ASort (id,Cic.CProp u) -> idref id (Ast.Sort (`CProp u))
     | Cic.AImplicit (id, Some `Hole) -> idref id Ast.UserInput
     | Cic.AImplicit (id, _) -> idref id Ast.Implicit
     | Cic.AProd (id,n,s,t) ->
         let binder_kind =
           match sort_of_id id with
           | `Set | `Type _ -> `Pi
-          | `Prop | `CProp -> `Forall
+          | `Prop | `CProp -> `Forall
         in
         idref id (Ast.Binder (binder_kind,
           (CicNotationUtil.name_of_cic_name n, Some (k s)), k t))
@@ -118,40 +118,31 @@ let ast_of_acic0 ~output_type term_info acic k =
     | Cic.ALambda (id,n,s,t) ->
         idref id (Ast.Binder (`Lambda,
           (CicNotationUtil.name_of_cic_name n, Some (k s)), k t))
-    | Cic.ALetIn (id,n,s,t) ->
-        idref id (Ast.LetIn ((CicNotationUtil.name_of_cic_name n, None),
+    | Cic.ALetIn (id,n,s,ty,t) ->
+        idref id (Ast.LetIn ((CicNotationUtil.name_of_cic_name n, Some (k ty)),
           k s, k t))
     | Cic.AAppl (aid,(Cic.AConst _ as he::tl as args))
     | Cic.AAppl (aid,(Cic.AMutInd _ as he::tl as args))
     | Cic.AAppl (aid,(Cic.AMutConstruct _ as he::tl as args)) as t ->
-       let last_n n l =
-         let rec aux =
-          function
-             [] -> assert false
-           | [_] as l -> l,1
-           | he::tl ->
-              let (res,len) as res' = aux tl in
-               if len < n then
-                he::res,len + 1
-               else
-                res'
-         in
-          match fst (aux l) with
-             [] -> assert false
-           | [t] -> t
-           | Ast.AttributedTerm (_,(Ast.Appl l))::tl -> 
-               idref aid (Ast.Appl (l@tl))
-           | l -> idref aid (Ast.Appl l)
-       in
        (match LibraryObjects.destroy_nat t with
        | Some n -> idref aid (Ast.Num (string_of_int n, -1))
        | None ->
            let deannot_he = Deannotate.deannotate_term he in
-           if CoercDb.is_a_coercion' deannot_he && !Acic2content.hide_coercions
-           then
-             (match CoercDb.is_a_coercion_to_funclass deannot_he with
-             | None -> idref aid (last_n 1 (List.map k tl))
-             | Some i -> idref aid (last_n (i+1) (List.map k tl)))
+           let coercion_info = CoercDb.is_a_coercion deannot_he in
+           if coercion_info <> None && !Acic2content.hide_coercions then
+             match coercion_info with
+             | None -> assert false 
+             | Some (_,_,_,sats,cpos) -> 
+                 if cpos < List.length tl then
+                   let _,rest = 
+                     try HExtlib.split_nth (cpos+sats+1) tl with Failure _ -> [],[] 
+                   in
+                   if rest = [] then
+                     idref aid (List.nth (List.map k tl) cpos)
+                   else
+                     idref aid (Ast.Appl (List.map k (List.nth tl cpos::rest)))
+                 else
+                   idref aid (Ast.Appl (List.map k tl))
            else
              idref aid (Ast.Appl (List.map k args)))
     | Cic.AAppl (aid,args) ->
@@ -309,7 +300,11 @@ let add_idrefs =
 let instantiate32 term_info idrefs env symbol args =
   let rec instantiate_arg = function
     | Ast.IdentArg (n, name) ->
-        let t = (try List.assoc name env with Not_found -> assert false) in
+        let t = 
+          try List.assoc name env 
+          with Not_found -> prerr_endline ("name not found in env: "^name);
+                            assert false
+        in
         let rec count_lambda = function
           | Ast.AttributedTerm (_, t) -> count_lambda t
           | Ast.Binder (`Lambda, _, body) -> 1 + count_lambda body
@@ -377,7 +372,11 @@ let ast_of_acic ~output_type id_to_sort annterm =
   ast, term_info.uri
 
 let counter = ref ~-1 
-let reset () = counter := ~-1;;
+let reset () =
+ counter := ~-1;
+ Hashtbl.clear level2_patterns32;
+ Hashtbl.clear interpretations
+;;
 let fresh_id =
   fun () ->
     incr counter;
@@ -439,7 +438,7 @@ let lookup_interpretations symbol =
 
 let remove_interpretation id =
   (try
-    let _, symbol, _, _ = Hashtbl.find level2_patterns32 id in
+    let dsc, symbol, _, _ = Hashtbl.find level2_patterns32 id in
     let ids = Hashtbl.find interpretations symbol in
     ids := List.filter ((<>) id) !ids;
     Hashtbl.remove level2_patterns32 id;