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