]> matita.cs.unibo.it Git - helm.git/blob - matita/components/ng_cic_content/interpretations.ml
Most warnings turned into errors and avoided
[helm.git] / matita / components / ng_cic_content / interpretations.ml
1 (* Copyright (C) 2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 open Printf
29
30 module Ast = NotationPt
31
32
33 let debug = false
34 let debug_print s = if debug then prerr_endline (Lazy.force s) else ()
35
36 type id = string
37 let hide_coercions = ref true;;
38
39 type cic_id = string
40
41 type term_info =
42   { sort: (cic_id, Ast.sort_kind) Hashtbl.t;
43     uri: (cic_id, NReference.reference) Hashtbl.t;
44   }
45
46 module IntMap = Map.Make(struct type t = int let compare = compare end);;
47 module StringMap = Map.Make(String);;
48
49 type db = {
50   counter: int;
51   pattern32_matrix: (bool * NotationPt.cic_appl_pattern * int) list;
52   level2_patterns32:
53    (string * string * NotationPt.argument_pattern list *
54      NotationPt.cic_appl_pattern) IntMap.t;
55   interpretations: int list StringMap.t; (* symb -> id list *)
56   compiled32:
57    (NCic.term -> ((string * NCic.term) list * NCic.term list * int) option)
58     Lazy.t
59 }
60
61 let initial_db status = {
62    counter = -1; 
63    pattern32_matrix = [];
64    level2_patterns32 = IntMap.empty;
65    interpretations = StringMap.empty;
66    compiled32 = lazy (Ncic2astMatcher.Matcher32.compiler status [])
67 }
68
69 class type g_status =
70   object
71     inherit NCicCoercion.g_status
72     method interp_db: db
73   end
74  
75 class virtual status =
76  object(self)
77    inherit NCicCoercion.status
78    val mutable interp_db = None (* mutable only to initialize it :-( *)
79    method interp_db = match interp_db with None -> assert false | Some x -> x
80    method set_interp_db v = {< interp_db = Some v >}
81    method set_interp_status
82     : 'status. #g_status as 'status -> 'self
83     = fun o -> {< interp_db = Some o#interp_db >}#set_coercion_status o
84    initializer
85     interp_db <- Some (initial_db self)
86  end
87
88 let idref register_ref =
89  let id = ref 0 in
90   fun ?reference t ->
91    incr id;
92    let id = "i" ^ string_of_int !id in
93     (match reference with None -> () | Some r -> register_ref id r);
94     Ast.AttributedTerm (`IdRef id, t)
95 ;;
96
97 let level_of_uri u = 
98   let name = NUri.name_of_uri u in
99   assert(String.length name > String.length "Type");
100   String.sub name 4 (String.length name - 4)
101 ;;
102
103 let find_level2_patterns32 status pid =
104  IntMap.find pid status#interp_db.level2_patterns32
105
106 let add_idrefs =
107   List.fold_right (fun idref t -> Ast.AttributedTerm (`IdRef idref, t))
108
109 let instantiate32 idrefs env symbol args =
110   let instantiate_arg = function
111     | Ast.IdentArg (n, name) ->
112         let t = 
113           try List.assoc name env 
114           with Not_found -> prerr_endline ("name not found in env: "^name);
115                             assert false
116         in
117         let rec count_lambda = function
118           | Ast.AttributedTerm (_, t) -> count_lambda t
119           | Ast.Binder (`Lambda, _, body) -> 1 + count_lambda body
120           | _ -> 0
121         in
122         let rec add_lambda t n =
123           if n > 0 then
124             let name = NotationUtil.fresh_name () in
125             Ast.Binder (`Lambda, (Ast.Ident (name, None), None),
126               Ast.Appl [add_lambda t (n - 1); Ast.Ident (name, None)])
127           else
128             t
129         in
130         add_lambda t (n - count_lambda t)
131   in
132   let head =
133     let symbol = Ast.Symbol (symbol, 0) in
134     add_idrefs idrefs symbol
135   in
136   if args = [] then head
137   else Ast.Appl (head :: List.map instantiate_arg args)
138
139 let fresh_id status =
140   let counter = status#interp_db.counter+1 in
141    status#set_interp_db ({ status#interp_db with counter = counter  }), counter
142
143 let load_patterns32 status t =
144  let t =
145   HExtlib.filter_map (function (true, ap, id) -> Some (ap, id) | _ -> None) t
146  in
147   status#set_interp_db
148    {status#interp_db with
149      compiled32 = lazy (Ncic2astMatcher.Matcher32.compiler status t) }
150 ;;
151
152 let add_interpretation status dsc (symbol, args) appl_pattern =
153   let status,id = fresh_id status in
154   let ids =
155    try
156     id::StringMap.find symbol status#interp_db.interpretations
157    with Not_found -> [id] in
158   let status =
159    status#set_interp_db { status#interp_db with
160     level2_patterns32 =
161       IntMap.add id (dsc, symbol, args, appl_pattern)
162        status#interp_db.level2_patterns32;
163     pattern32_matrix = (true,appl_pattern,id)::status#interp_db.pattern32_matrix;
164     interpretations = StringMap.add symbol ids status#interp_db.interpretations
165    }
166   in
167    load_patterns32 status status#interp_db.pattern32_matrix
168
169 let toggle_active_interpretations status b =
170   status#set_interp_db { status#interp_db with
171    pattern32_matrix =
172      List.map (fun (_,ap,id) -> b,ap,id) status#interp_db.pattern32_matrix }
173
174 exception Interpretation_not_found
175
176 let lookup_interpretations status ?(sorted=true) symbol =
177   try
178     let raw = 
179       List.map (
180         fun id ->
181           let (dsc, _, args, appl_pattern) =
182             try IntMap.find id status#interp_db.level2_patterns32
183             with Not_found -> assert false 
184           in
185           dsc, args, appl_pattern
186       ) (StringMap.find symbol status#interp_db.interpretations)
187     in
188     if sorted then HExtlib.list_uniq (List.sort Pervasives.compare raw)
189               else raw
190   with Not_found -> raise Interpretation_not_found
191
192 let instantiate_appl_pattern 
193   ~mk_appl ~mk_implicit ~term_of_nref env appl_pattern 
194 =
195   let lookup name =
196     try List.assoc name env
197     with Not_found ->
198       prerr_endline (sprintf "Name %s not found" name);
199       assert false
200   in
201   let rec aux = function
202     | Ast.NRefPattern nref -> term_of_nref nref
203     | Ast.ImplicitPattern -> mk_implicit false
204     | Ast.VarPattern name -> lookup name
205     | Ast.ApplPattern terms -> mk_appl (List.map aux terms)
206   in
207   aux appl_pattern
208
209 let destroy_nat =
210   let is_nat_URI = NUri.eq (NUri.uri_of_string
211   "cic:/matita/arithmetics/nat/nat.ind") in
212   let is_zero = function
213     | NCic.Const (NReference.Ref (uri, NReference.Con (0, 1, 0))) when
214        is_nat_URI uri -> true
215     | _ -> false
216   in
217   let is_succ = function
218     | NCic.Const (NReference.Ref (uri, NReference.Con (0, 2, 0))) when
219        is_nat_URI uri -> true
220     | _ -> false
221   in
222   let rec aux acc = function
223     | NCic.Appl [he ; tl] when is_succ he -> aux (acc + 1) tl
224     | t when is_zero t -> Some acc
225     | _ -> None
226   in
227    aux 0
228
229 (* CODICE c&p da NCicPp *)
230 let nast_of_cic0 status
231  ~(idref:
232     ?reference:NReference.reference -> NotationPt.term -> NotationPt.term)
233  ~output_type ~metasenv ~subst k ~context =
234   function
235     | NCic.Rel n ->
236        (try 
237          let name,_ = List.nth context (n-1) in
238          let name = if name = "_" then "__"^string_of_int n else name in
239           idref (Ast.Ident (name,None))
240         with Failure "nth" | Invalid_argument "List.nth" -> 
241          idref (Ast.Ident ("-" ^ string_of_int (n - List.length context),None)))
242     | NCic.Const r -> idref ~reference:r (Ast.Ident (NCicPp.r2s status true r, None))
243     | NCic.Meta (n,lc) when List.mem_assoc n subst -> 
244         let _,_,t,_ = List.assoc n subst in
245          k ~context (NCicSubstitution.subst_meta status lc t)
246     | NCic.Meta (n,(s,l)) ->
247        (* CSC: qua non dovremmo espandere *)
248        let l = NCicUtils.expand_local_context l in
249         idref (Ast.Meta
250          (n, List.map (fun x -> Some (k ~context (NCicSubstitution.lift status s x))) l))
251     | NCic.Sort NCic.Prop -> idref (Ast.Sort `Prop)
252     | NCic.Sort NCic.Type [] -> idref (Ast.Sort `Set)
253     | NCic.Sort NCic.Type ((`Type,u)::_) -> 
254               idref(Ast.Sort (`NType (level_of_uri u)))
255     | NCic.Sort NCic.Type ((`CProp,u)::_) -> 
256               idref(Ast.Sort (`NCProp (level_of_uri u)))
257     | NCic.Sort NCic.Type ((`Succ,u)::_) -> 
258               idref(Ast.Sort (`NType (level_of_uri u ^ "+1")))
259     | NCic.Implicit `Hole -> idref (Ast.UserInput)
260     | NCic.Implicit `Vector -> idref (Ast.Implicit `Vector)
261     | NCic.Implicit _ -> idref (Ast.Implicit `JustOne)
262     | NCic.Prod (n,s,t) ->
263         let n = if n.[0] = '_' then "_" else n in
264         let binder_kind = `Forall in
265          idref (Ast.Binder (binder_kind, (Ast.Ident (n,None), Some (k ~context s)),
266           k ~context:((n,NCic.Decl s)::context) t))
267     | NCic.Lambda (n,s,t) ->
268         idref (Ast.Binder (`Lambda,(Ast.Ident (n,None), Some (k ~context s)),
269          k ~context:((n,NCic.Decl s)::context) t))
270     | NCic.LetIn (_n,s,ty,NCic.Rel 1) ->
271         idref (Ast.Cast (k ~context ty, k ~context s))
272     | NCic.LetIn (n,s,ty,t) ->
273         idref (Ast.LetIn ((Ast.Ident (n,None), Some (k ~context s)), k ~context
274           ty, k ~context:((n,NCic.Decl s)::context) t))
275     | NCic.Appl (NCic.Meta (n,lc) :: args) when List.mem_assoc n subst -> 
276        let _,_,t,_ = List.assoc n subst in
277        let hd = NCicSubstitution.subst_meta status lc t in
278         k ~context
279          (NCicReduction.head_beta_reduce status ~upto:(List.length args)
280            (match hd with
281            | NCic.Appl l -> NCic.Appl (l@args)
282            | _ -> NCic.Appl (hd :: args)))
283     | NCic.Appl args as t ->
284        (match destroy_nat t with
285          | Some n -> idref (Ast.Num (string_of_int n, -1))
286          | None ->
287             let args =
288              if not !hide_coercions then args
289              else
290               match
291                NCicCoercion.match_coercion status ~metasenv ~context ~subst t
292               with
293                | None -> args
294                | Some (_,sats,cpos) -> 
295 (* CSC: sats e' il numero di pi, ma non so cosa farmene! voglio il numero di
296    argomenti da saltare, come prima! *)
297                   if cpos < List.length args - 1 then
298                    List.nth args (cpos + 1) ::
299                     try snd (HExtlib.split_nth (cpos+sats+2) args)
300                     with Failure _->[]
301                   else
302                    args
303             in
304              (match args with
305                  [arg] -> idref (k ~context arg)
306                | _ -> idref (Ast.Appl (List.map (k ~context) args))))
307     | NCic.Match (NReference.Ref (uri,_) as r,outty,te,patterns) ->
308        (try
309         let name = NUri.name_of_uri uri in
310 (* CSC
311         let uri_str = UriManager.string_of_uri uri in
312         let puri_str = sprintf "%s#xpointer(1/%d)" uri_str (typeno+1) in
313         let ctor_puri j =
314           UriManager.uri_of_string
315             (sprintf "%s#xpointer(1/%d/%d)" uri_str (typeno+1) j)
316         in
317 *)
318         let case_indty =
319          name, None(*CSC Some (UriManager.uri_of_string puri_str)*) in
320         let constructors, leftno =
321          let _,leftno,tys,_,n = NCicEnvironment.get_checked_indtys status r in
322          let _,_,_,cl  = List.nth tys n in
323           cl,leftno
324         in
325         let rec eat_branch n ctx ty pat =
326           match (ty, pat) with
327           | NCic.Prod (_name, _s, t), _ when n > 0 ->
328              eat_branch (pred n) ctx t pat 
329           | NCic.Prod (_, _, t), NCic.Lambda (name, s, t') ->
330               let cv, rhs = eat_branch 0 ((name,NCic.Decl s)::ctx) t t' in
331               (Ast.Ident (name,None), Some (k ~context:ctx s)) :: cv, rhs
332           | _, _ -> [], k ~context:ctx pat
333         in
334         let j = ref 0 in
335         let patterns =
336           try
337             List.map2
338               (fun (_, name, ty) pat ->
339                 incr j;
340                 let name,(capture_variables,rhs) =
341                  match output_type with
342                     `Term -> name, eat_branch leftno context ty pat
343                   | `Pattern -> "_", ([], k ~context pat)
344                 in
345                  Ast.Pattern (name, None(*CSC Some (ctor_puri !j)*), capture_variables), rhs
346               ) constructors patterns
347           with Invalid_argument _ -> assert false
348         in
349         let indty =
350          match output_type with
351             `Pattern -> None
352           | `Term -> Some case_indty
353         in
354          idref (Ast.Case (k ~context te, indty, Some (k ~context outty), patterns))
355      with
356       NCicEnvironment.ObjectNotFound msg ->
357        idref (Ast.Case(k ~context te,Some ("NOT_FOUND: " ^ Lazy.force msg,None),
358        Some (k ~context outty),
359        (List.map (fun t -> Ast.Pattern ("????", None, []), k ~context t)
360          patterns))))
361 ;;
362
363 let rec nast_of_cic1 status ~idref ~output_type ~metasenv ~subst ~context term =
364   match Lazy.force status#interp_db.compiled32 term with
365   | None ->
366      nast_of_cic0 status ~idref ~output_type ~metasenv ~subst
367       (nast_of_cic1 status ~idref ~output_type ~metasenv ~subst) ~context term 
368   | Some (env, ctors, pid) -> 
369       let idrefs =
370        List.map
371         (fun term ->
372           let attrterm =
373            idref
374             ~reference:
375               (match term with NCic.Const nref -> nref | _ -> assert false)
376            (NotationPt.Ident ("dummy",None))
377           in
378            match attrterm with
379               Ast.AttributedTerm (`IdRef id, _) -> id
380             | _ -> assert false
381         ) ctors
382       in
383       let env =
384        List.map
385         (fun (name, term) ->
386           name,
387            nast_of_cic1 status ~idref ~output_type ~subst ~metasenv ~context
388             term
389         ) env
390       in
391       let _, symbol, args, _ =
392         try
393          find_level2_patterns32 status pid
394         with Not_found -> assert false
395       in
396       let ast = instantiate32 idrefs env symbol args in
397       idref ast (*Ast.AttributedTerm (`IdRef (idref term), ast)*)
398 ;;
399
400 let nmap_context0 status ~idref ~metasenv ~subst context =
401  let module K = Content in
402  let nast_of_cic =
403   nast_of_cic1 status ~idref ~output_type:`Term ~metasenv ~subst
404  in
405  fst (
406   List.fold_right
407    (fun item (res,context) ->
408      match item with
409       | name,NCic.Decl t ->
410          Some
411           (* We should call build_decl_item, but we have not computed *)
412           (* the inner-types ==> we always produce a declaration      *)
413           (`Declaration
414             { K.dec_name = (Some name);
415               K.dec_id = "-1"; 
416               K.dec_inductive = false;
417               K.dec_aref = "-1";
418               K.dec_type = nast_of_cic ~context t
419             })::res,item::context
420       | name,NCic.Def (t,ty) ->
421          Some
422           (* We should call build_def_item, but we have not computed *)
423           (* the inner-types ==> we always produce a declaration     *)
424           (`Definition
425              { K.def_name = (Some name);
426                K.def_id = "-1"; 
427                K.def_aref = "-1";
428                K.def_term = nast_of_cic ~context t;
429                K.def_type = nast_of_cic ~context ty
430              })::res,item::context
431    ) context ([],[]))
432 ;;
433
434 let nmap_sequent0 status ~idref ~metasenv ~subst (i,(_n,context,ty)) =
435  let module K = Content in
436  let nast_of_cic =
437   nast_of_cic1 status ~idref ~output_type:`Term ~metasenv ~subst in
438  let context' = nmap_context0 status ~idref ~metasenv ~subst context in
439   ("-1",i,context',nast_of_cic ~context ty)
440 ;;
441
442 let object_prefix = "obj:";;
443 let declaration_prefix = "decl:";;
444 let definition_prefix = "def:";;
445 let inductive_prefix = "ind:";;
446 let joint_prefix = "joint:";;
447
448 let get_id =
449  function
450     Ast.AttributedTerm (`IdRef id, _) -> id
451   | _ -> assert false
452 ;;
453
454 let gen_id prefix seed =
455  let res = prefix ^ string_of_int !seed in
456   incr seed ;
457   res
458 ;;
459
460 let build_def_item seed _context _metasenv id n t ty =
461  let module K = Content in
462 (*
463   try
464    let sort = Hashtbl.find ids_to_inner_sorts id in
465    if sort = `Prop then
466        (let p = 
467         (acic2content seed context metasenv ?name:(name_of n) ~ids_to_inner_sorts  ~ids_to_inner_types t)
468        in 
469         `Proof p;)
470    else 
471 *)
472       `Definition
473         { K.def_name = Some n;
474           K.def_id = gen_id definition_prefix seed; 
475           K.def_aref = id;
476           K.def_term = t;
477           K.def_type = ty
478         }
479 (*
480   with
481    Not_found -> assert false
482 *)
483
484 let build_decl_item seed id n s =
485  let module K = Content in
486 (*
487  let sort =
488    try
489     Some (Hashtbl.find ids_to_inner_sorts (Cic2acic.source_id_of_id id))
490    with Not_found -> None
491  in
492  match sort with
493  | Some `Prop ->
494     `Hypothesis
495       { K.dec_name = name_of n;
496         K.dec_id = gen_id declaration_prefix seed; 
497         K.dec_inductive = false;
498         K.dec_aref = id;
499         K.dec_type = s
500       }
501  | _ ->
502 *)
503     `Declaration
504       { K.dec_name = Some n;
505         K.dec_id = gen_id declaration_prefix seed; 
506         K.dec_inductive = false;
507         K.dec_aref = id;
508         K.dec_type = s
509       }
510 ;;
511
512 let nmap_cobj0 status ~idref (uri,_,metasenv,subst,kind) =
513   let module K = Content in
514   let nast_of_cic =
515    nast_of_cic1 status ~idref ~output_type:`Term ~metasenv ~subst in
516   let seed = ref 0 in
517   let conjectures =
518    match metasenv with
519       [] -> None
520     | _ -> (*Some (List.map (map_conjectures seed) metasenv)*)
521       (*CSC: used to be the previous line, that uses seed *)
522       Some (List.map (nmap_sequent0 status ~idref ~metasenv ~subst) metasenv)
523   in
524 let  build_constructors seed l =
525       List.map 
526        (fun (_,n,ty) ->
527            let ty = nast_of_cic ~context:[] ty in
528            { K.dec_name = Some n;
529              K.dec_id = gen_id declaration_prefix seed;
530              K.dec_inductive = false;
531              K.dec_aref = "";
532              K.dec_type = ty
533            }) l
534 in
535 let build_inductive b seed = 
536       fun (_,n,ty,cl) ->
537         let ty = nast_of_cic ~context:[] ty in
538         `Inductive
539           { K.inductive_id = gen_id inductive_prefix seed;
540             K.inductive_name = n;
541             K.inductive_kind = b;
542             K.inductive_type = ty;
543             K.inductive_constructors = build_constructors seed cl
544            }
545 in
546 let build_fixpoint _b seed = 
547       fun (_,n,_,ty,t) ->
548         let t = nast_of_cic ~context:[] t in
549         let ty = nast_of_cic ~context:[] ty in
550         `Definition
551           { K.def_id = gen_id inductive_prefix seed;
552             K.def_name = Some n;
553             K.def_aref = "";
554             K.def_type = ty;
555             K.def_term = t;
556            }
557 in
558  match kind with
559   | NCic.Fixpoint (is_rec, ifl, _) -> 
560        (gen_id object_prefix seed, conjectures,
561           `Joint
562             { K.joint_id = gen_id joint_prefix seed;
563               K.joint_kind = 
564                  if is_rec then 
565                       `Recursive (List.map (fun (_,_,i,_,_) -> i) ifl)
566                  else `CoRecursive;
567               K.joint_defs = List.map (build_fixpoint is_rec seed) ifl
568             }) 
569   | NCic.Inductive (is_ind, lno, itl, _) ->
570        (gen_id object_prefix seed, conjectures,
571           `Joint
572             { K.joint_id = gen_id joint_prefix seed;
573               K.joint_kind = 
574                  if is_ind then `Inductive lno else `CoInductive lno;
575               K.joint_defs = List.map (build_inductive is_ind seed) itl
576             }) 
577   | NCic.Constant (_,_,Some bo,ty,_) ->
578      let ty = nast_of_cic ~context:[] ty in
579      let bo = nast_of_cic ~context:[] bo in
580       (gen_id object_prefix seed, conjectures,
581         `Def (K.Const,ty,
582           build_def_item seed [] [] (get_id bo) (NUri.name_of_uri uri) bo ty))
583   | NCic.Constant (_,_,None,ty,_) ->
584      let ty = nast_of_cic ~context:[] ty in
585        (gen_id object_prefix seed, conjectures,
586          `Decl (K.Const,
587            (*CSC: ??? get_id ty here used to be the id of the axiom! *)
588            build_decl_item seed (get_id ty) (NUri.name_of_uri uri) ty))
589 ;;
590
591 let with_idrefs foo status obj =
592  let ids_to_refs = Hashtbl.create 211 in
593  let register_ref = Hashtbl.add ids_to_refs in
594   foo status ~idref:(idref register_ref) obj, ids_to_refs
595 ;;
596
597 let nmap_cobj status = with_idrefs nmap_cobj0 status
598
599 let nmap_sequent status ~metasenv ~subst =
600  with_idrefs (nmap_sequent0 ~metasenv ~subst) status
601
602 let nmap_term status ~metasenv ~subst ~context =
603  with_idrefs (nast_of_cic1 ~output_type:`Term ~metasenv ~subst ~context) status
604
605 let nmap_context status ~metasenv ~subst =
606  with_idrefs (nmap_context0 ~metasenv ~subst) status
607
608 (* FG ***********************************************************************)
609
610 let nmap_obj0 status ~idref (_, _, metasenv, subst, kind) =
611    let module N = NotationPt in
612    let nast_of_cic =
613       nast_of_cic1 status ~idref ~output_type:`Term ~metasenv ~subst
614    in
615    let rec mk_captures lno k c u = match lno, u with
616       | 0, _                                -> k, c
617       | _, NCic.Prod (n, w, u) when lno > 0 ->
618          let cap = nast_of_cic ~context:c w, None in
619          let hyp = n, NCic.Decl w in
620          mk_captures (pred lno) (cap :: k) (hyp :: c) u
621       | _                                 -> assert false
622    in
623    let build_captures lno = function
624       | []                -> [], []
625       | (_, _, u, _) :: _ -> mk_captures lno [] [] u
626    in
627    let rec eat_prods prods lno t = match prods, lno, t with
628       | _, 0, _                                      -> t
629       | true, _, NCic.Prod (_, _, t) when lno > 0    -> eat_prods prods (pred lno) t
630       | false, _, NCic.Lambda (_, _, t) when lno > 0 -> eat_prods prods (pred lno) t
631       | _                                            -> assert false
632    in
633    let build_constractor lno context (_, n, bo) =
634       let bo = nast_of_cic ~context (eat_prods false lno bo) in      
635       n, bo
636    in
637    let build_inductive is_ind lno context (_, n, ty, cl) =
638       let ty = nast_of_cic ~context (eat_prods true lno ty) in
639       n, is_ind, ty, List.map (build_constractor lno context) cl
640    in
641    match kind with
642       | NCic.Constant (_, n, xbo, ty, attrs) ->
643          let ty = nast_of_cic ~context:[] ty in
644          let xbo = match xbo with 
645             | Some bo -> Some (nast_of_cic ~context:[] bo)
646             | None    -> None
647          in
648          N.Theorem (n, ty, xbo, attrs)
649       | NCic.Inductive (is_ind, lno, itl, (src, `Regular)) ->      
650          let captures, context = build_captures lno itl in
651          N.Inductive (captures, List.map (build_inductive is_ind lno context) itl, src)
652       | _ -> assert false  (* NCic.Fixpoint (is_rec, ifl, _) -> *)
653
654 let nmap_obj status = with_idrefs nmap_obj0 status